package com.product.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shopgoods.common.log.annotation.Log;
import com.shopgoods.common.log.enums.BusinessType;
import com.shopgoods.common.security.annotation.RequiresPermissions;
import com.product.system.domain.PmsProduct;
import com.product.system.service.IPmsProductService;
import com.shopgoods.common.core.web.controller.BaseController;
import com.shopgoods.common.core.web.domain.AjaxResult;
import com.shopgoods.common.core.utils.poi.ExcelUtil;
import com.shopgoods.common.core.web.page.TableDataInfo;

/**
 * 商品信息Controller
 *
 * @author GYW
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/product")
public class PmsProductController extends BaseController
{
    @Autowired
    private IPmsProductService pmsProductService;

    /**
     * 查询商品信息列表
     */
    @RequiresPermissions("system:product:list")
    @GetMapping("/list")
    public TableDataInfo list(PmsProduct pmsProduct)
    {
        startPage();
        List<PmsProduct> list = pmsProductService.selectPmsProductList(pmsProduct);
        return getDataTable(list);
    }

    /**
     * 导出商品信息列表
     */
    @RequiresPermissions("system:product:export")
    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsProduct pmsProduct)
    {
        List<PmsProduct> list = pmsProductService.selectPmsProductList(pmsProduct);
        ExcelUtil<PmsProduct> util = new ExcelUtil<PmsProduct>(PmsProduct.class);
        util.exportExcel(response, list, "商品信息数据");
    }

    /**
     * 获取商品信息详细信息
     */
    @RequiresPermissions("system:product:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(pmsProductService.selectPmsProductById(id));
    }

    /**
     * 新增商品信息
     */
    @RequiresPermissions("system:product:add")
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsProduct pmsProduct)
    {
        return toAjax(pmsProductService.insertPmsProduct(pmsProduct));
    }

    /**
     * 修改商品信息
     */
    @RequiresPermissions("system:product:edit")
    @Log(title = "商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsProduct pmsProduct)
    {
        return toAjax(pmsProductService.updatePmsProduct(pmsProduct));
    }

    /**
     * 删除商品信息
     */
    @RequiresPermissions("system:product:remove")
    @Log(title = "商品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(pmsProductService.deletePmsProductByIds(ids));
    }


    /**
     * 修改商品上架状态的变化
     */
    @PutMapping("/updatePublishStatusData")
    public AjaxResult updatePublishStatusData(@RequestBody PmsProduct pmsProduct)
    {
        return toAjax(pmsProductService.updatePublishStatusData(pmsProduct));
    }


    /**
     * 修改商品上架状态的变化
     */
    @PutMapping("/updateNewStatusData")
    public AjaxResult updateNewStatusData(@RequestBody PmsProduct pmsProduct)
    {
        return toAjax(pmsProductService.updateNewStatusData(pmsProduct));
    }

    /**
     * 修改商品上架状态的变化
     */
    @PutMapping("/updateRecommandStatusData")
    public AjaxResult updateRecommandStatusData(@RequestBody PmsProduct pmsProduct)
    {
        return toAjax(pmsProductService.updateRecommandStatusData(pmsProduct));
    }





}
